# StartTCL: n
#
 namespace eval newspellscripts {
 variable spell_scripts
 array set spell_scripts {
  24275 { ::FinishingMoves::WrathHammer $to $from 11976 }
  24274 { ::FinishingMoves::WrathHammer $to $from 13584 }
  24239 { ::FinishingMoves::WrathHammer $to $from 12057 }
  5308 { ::FinishingMoves::Execute $to $from 13446 }
  20658 { ::FinishingMoves::Execute $to $from 14516 }
  20660 { ::FinishingMoves::Execute $to $from 15580 }
  20661 { ::FinishingMoves::Execute $to $from 18368 }
  20662 { ::FinishingMoves::Execute $to $from 22591 }
  100 { ::ChargeSkills::Charge $to $from }
  6178 { ::ChargeSkills::Charge $to $from }
  11578 { ::ChargeSkills::Charge $to $from }
  12695 { ::ChargeSkills::ChargeStun $from }
  20252 { ::ChargeSkills::Intercept1 $to $from }
  20616 { ::ChargeSkills::Intercept2 $to $from }
  20617 { ::ChargeSkills::Intercept3 $to $from }
  14530 { ::ChargeSkills::InterceptStun1 $from }
  17498 { ::ChargeSkills::InterceptStun2 $from }
  22863 { ::ChargeSkills::InterceptStun3 $from }
  921 { ::vor::vol $from $to }
 20187 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright01"
 } 
 20287 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright02"
 } 
 20288 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright03"
 } 
 20289 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright04"
 } 
 20290 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright05"
 } 
 20291 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright06"
 } 
 20292 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright07"
 } 
 20293 { 
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auraright08"
 } 
 20375 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auracommand01"
 } 
 20915 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auracommand02"
 } 
 20918 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auracommand03"
 } 
 20919 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auracommand04"
 } 
 20920 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auracommand05"
 } 
 20165 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auralight01"
 } 
 20347 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auralight02"
 } 
 20348 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auralight03"
 } 
 20349 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "auralight04"
 } 
 20166 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "aurawisd01"
 }
 20356 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "aurawisd02"
 }
 20357 {
 ::Judgement::ClearAura $from
 ::SetQFlag $from "aurawisd03"
 }
 20271 { ::Judgement::Judge $from $to }
 13797 { ::HunterTraps::DismissTrap $from }
 14298 { ::HunterTraps::DismissTrap $from }
 14299 { ::HunterTraps::DismissTrap $from }
 14300 { ::HunterTraps::DismissTrap $from }
 14301 { ::HunterTraps::DismissTrap $from }
 3355 { ::HunterTraps::DismissTrap $from }
 14308 { ::HunterTraps::DismissTrap $from }
 14309 { ::HunterTraps::DismissTrap $from }
 13810 { ::HunterTraps::DismissTrap $from }
 13812 { ::HunterTraps::DismissTrap $from }
 14314 { ::HunterTraps::DismissTrap $from }
 14315 { ::HunterTraps::DismissTrap $from }
 }
}

#
# 02.06 Fixes
#
namespace eval Judgement {
proc ClearAura { player } {
	ClearQFlag $player "auraright01"
	ClearQFlag $player "auraright02"
	ClearQFlag $player "auraright03"
	ClearQFlag $player "auraright04"
	ClearQFlag $player "auraright05"
	ClearQFlag $player "auraright06"
	ClearQFlag $player "auraright07"
	ClearQFlag $player "auraright08"
	ClearQFlag $player "auracommand01"
	ClearQFlag $player "auracommand02"
	ClearQFlag $player "auracommand03"
	ClearQFlag $player "auracommand04"
	ClearQFlag $player "auracommand05"
	ClearQFlag $player "auralight01"
	ClearQFlag $player "auralight02"
	ClearQFlag $player "auralight03"
	ClearQFlag $player "auralight04"
	ClearQFlag $player "aurawisd01"
	ClearQFlag $player "aurawisd02"
	ClearQFlag $player "aurawisd03"
	return 0
}

proc Judge { player ennemy } {
if {[GetQFlag $player "auraright01"]} {
		::CastSpell $player $ennemy 20187
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright02"]} {
		::CastSpell $player $ennemy 20280
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright03"]} {
		::CastSpell $player $ennemy 20281
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright04"]} {
		::CastSpell $player $ennemy 20282
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright05"]} {
		::CastSpell $player $ennemy 20283
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright06"]} {
		::CastSpell $player $ennemy 20284
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright07"]} {
		::CastSpell $player $ennemy 20285
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auraright08"]} {
		::CastSpell $player $ennemy 20286
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auracommand01"]} {
		::CastSpell $player $ennemy 20467
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auracommand02"]} {
		::CastSpell $player $ennemy 20963
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auracommand03"]} {
		::CastSpell $player $ennemy 20964
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auracommand04"]} {
		::CastSpell $player $ennemy 20965
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auracommand05"]} {
		::CastSpell $player $ennemy 20966
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auralight01"]} {
		::CastSpell $player $player 30090
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auralight02"]} {
		::CastSpell $player $player 30091
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auralight03"]} {
		::CastSpell $player $player 30092
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "auralight04"]} {
		::CastSpell $player $player 30093
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "aurawisd01"]} {
		::CastSpell $player $player 30094
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "aurawisd02"]} {
		::CastSpell $player $player 30095
		::Judgement::ClearAura $player
		return 0
	}

	if {[GetQFlag $player "aurawisd03"]} {
		::CastSpell $player $player 30096
		::Judgement::ClearAura $player
		return 0
	}
}
}

#
# Stealth
#
proc ::newspellscripts::Stealth { to from spellid } { ::SetQFlag $from stealth }
::Custom::HookProc "::AI::CanAgro" {; if { [ ::GetQFlag $victim stealth ] } { return 0 } }
::Custom::HookProc "::WoWEmu::DamageReduction" { ::ClearQFlag $player stealth }
::Custom::AddSpellScript "::newspellscripts::Stealth" { 1784 1785 1786 1787 }

#
# FinishingMoves
#
namespace eval FinishingMoves { 
proc WrathHammer { to from spell } {; if { [GetHealthPCT $to] <=20} { CastSpell $from $to $spell } }
proc Execute { to from spell } {; if { [GetHealthPCT $to] <= 20} { CastSpell $from $to $spell } }
}

#
# ChargeSkills
#
namespace eval ChargeSkills { 
proc Charge { to from } {; CastSpell $from $from 12695 }
proc ChargeStun { from } {; CastSpell $from [GetSelection $from] 7922 }
proc Intercept1 { to from } {; CastSpell $from $from 14530 }
proc Intercept2 { to from } {; CastSpell $from $from 17498 }
proc Intercept3 { to from } {; CastSpell $from $from 22863 }
proc InterceptStun1 { from } {; CastSpell $from [GetSelection $from] 20253 }
proc InterceptStun2 { from } {; CastSpell $from [GetSelection $from] 20614 }
proc InterceptStun3 { from } {; CastSpell $from [GetSelection $from] 20615 }
}

#
# Bads Spell fixes...
#
 proc ::newspellscripts::BadspellsAdds { to from spellid } {
  variable spell_scripts
  eval $spell_scripts($spellid)
}

#
# TameSpell
#
proc ::newspellscripts::tamespell { to from spellid } {
 if { [GetLevel $from] < [GetLevel $to] || [::Custom::GetElite $to] > 0 || [ ::GetCreatureType $to ] == 7 || [ ::GetCreatureType $to ] == 8 } { return "You can't Tame this!" }
 CastSpell $from $to 13481
}

::Custom::AddSpellScript "::PetSyStem::addonproc" 883
::Custom::AddSpellScript "::newspellscripts::tamespell" 13481
::Custom::AddSpellScript "::newspellscripts::BadspellsAdds" { [array names ::newspellscripts::spell_scripts] }

#
#	Scripted Spell Procedures used in the Spell.DBC from BAD's Team
#
#
namespace eval ::SpellProcs {
	variable ::SpellProcs::SelfTriggers
	array set ::SpellProcs::SelfTriggers {
		465		30037
		10290	30038
		643		30039
		10291	30040
		1032	30041
		1032	30042
		10292	30042
		10293	30043
		7294	30044
		10298	30045
		10299	30046
		10300	30047
		10301	30048
		19876	30049
		19895	30050
		19896	30051
		19888	30052
		19897	30053
		19898	30054
		19891	30055
		19899	30056
		19900	30057
		1130	30058
		14323	30059
		14324	30060
		14325	30061
		6673	30062
		5242	30063
		6192	30064
		11549	30065
		11550	30066
		11551	30067
		30024	30068
		30025	30069
		19506	50109
		20905	50110
		20906	50111
		20043	50118
		20190	50119
		6940	50120
		20729	50121
		50123	20167
		50124	20333
		50125	20334
		50126	20340
		50147	20168
		50148	20350
		50149	20351
		14278	50127
		8233	50128
		8236	50129
		10484	50130
		16361	50131
		8516	50132
		10608	50133
		10610	50134
		17364	18941
		20178	18941
		16459   18941
		12964	50135
		23602	50135
	}
	#
	#	This spell procedure triggers a second spell on the caster.
	#
	proc SelfTrigger { to from spellid } {
		::CastSpell $from $from $::SpellProcs::SelfTriggers($spellid)
	}
}
::Custom::AddSpellScript "::SpellProcs::SelfTrigger" [ array names ::SpellProcs::SelfTriggers ]

namespace eval ::OnCrowdControl {
	proc UndoCrowdControl { to from spellid } {
		variable OnCrowdControl
		variable CrowdControlled
		if { [ info exists OnCrowdControl($from) ] && !( $CrowdControlled == $to ) } { 
			::CastSpell $CrowdControlled $CrowdControlled 22890
			set OnCrowdControl($from) 0 
		}
		set OnCrowdControl($from) 1
		set CrowdControlled $to
		return
	}
	proc Polymorph { to from spellid } { CastSpell $to $to 12939 }
}
variable CrowdControlSpells { 2878 5627 10326 339 1062 5195 5196 9852 9853 118 12824 12825 12826 6770 2070 11297 5782 6213 6215 9484 9485 10955 }
::Custom::AddSpellScript "::OnCrowdControl::UndoCrowdControl" $CrowdControlSpells
variable PolymorphSpells { 118 12824 12825 12826 }
::Custom::AddSpellScript "::OnCrowdControl::Polymorph" $PolymorphSpells

namespace eval ::Judgement {
	variable ::Judgement::Judgements
	array set ::Judgement::Judgements {
		20154	20187
		20287	20280
		20288	20281
		20289	20282
		20290	20283
		20291	20284
		20292	20285
		20293	20286
		20375	20467	
		20915	20963
		20918	20964
		20919	20965
		20920	20966
		20165	20185
		20347	20344
		20348	20345
		20349	20346
		20166	20186
		20356	20354
		20357	20355
		21082	21183
		21062	21088
		20305	20300
		20306	20301
		20307	20302
		20308	20303
		20271	0		
	}
	proc Judge { to from spellid } {
		variable Seal
		if { $spellid == 20271 } {
			if { [ info exists Seal($from) ] && [expr ($Seal($from) > 0) ] } {
				::CastSpell $from $to $Seal($from)
				set Seal($from) 0
				return
			}
			return
		}
		set Seal($from) $::Judgement::Judgements($spellid)
	}
}
::Custom::AddSpellScript "::Judgement::Judge" [ array names ::Judgement::Judgements ]
